package com.aaa.controller.back;

import com.aaa.entity.Supplier;
import com.aaa.service.back.SupplierService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RequestMapping("/supplier")
@Controller
public class SupplierController {

    @Resource
    private SupplierService supplierService;

    /**
     * 查询供应商信息
     * @return
     */
    @RequestMapping("/findSupplier")
    public String findSupplier(Model model){
        List<Map<String, Object>> supplierList = supplierService.findSupplier();
        model.addAttribute("supplierList",supplierList);
        return "back/supplier-list";
    }

    /**
     * 添加供应商信息显示
     * @return
     */
    @RequestMapping("/addSupplierShow")
    public String addSupplierShow(){
        return "back/supplier-add";
    }

    /**
     * 添加供应商信息
     * @param supplier
     * @return
     */
    @RequestMapping("/addSupplierSubmit")
    public String addSupplierSubmit(Supplier supplier){
        supplierService.addSupplier(supplier);
        return "back/supplier-list";
    }

    /**
     * 修改供应商信息显示
     * @return
     */
    @RequestMapping("/editSupplierShow")
    public String editSupplierShow(Model model,String supplierId){
        Map<String, Object> supplierMap = supplierService.findSupplierBySupplierId(supplierId);
        model.addAttribute("supplierMap",supplierMap);
        return "back/supplier-edit";
    }

    /**
     * 修改仓库信息
     * @param supplier
     * @return
     */
    @RequestMapping("/editSupplierSubmit")
    public String editSupplierSubmit(Supplier supplier){
        supplierService.editSupplier(supplier);
        return "back/supplier-list";
    }

}
